package entity;

import org.junit.Test;

import java.util.List;

public class Poem {
    private List<String> strains;
    private String author;
    private List<String> paragraphs;
    private String title;

    /**
     * 获得五言绝句四个半句中的一个
     * @param i 从1开始编号,i>=4时返回最后一个半句
     */
    public String getParagrahPart(int i){
        if (i==1){
            String para0 = paragraphs.get(0).replaceAll("（.*）","");
            if (para0.length()<5) {
                return para0.substring(0, para0.length()-1);
            }else {
                return para0.substring(0,5);
            }
        }else if (i==2){
            String para0 = paragraphs.get(0).replaceAll("（.*）","");
            //noinspection Duplicates
            if (para0.length()<5) {
                return null;
            }else {
                //noinspection Duplicates
                if (para0.length()<7)   return null;
                return para0.substring(6,para0.length()-1);
            }
        }else if (i==3){
            String para1 = paragraphs.get(1).replaceAll("（.*）","");
            if (para1.length()<5) {
                return para1.substring(0, para1.length()-1);
            }else {
                return para1.substring(0,5);
            }
        }else {
            String para1 = paragraphs.get(1).replaceAll("（.*）","");
            //noinspection Duplicates
            if (para1.length()<5) {
                return null;
            }else {
                if (para1.length()<7)   return null;
                return para1.substring(6,para1.length()-1);
            }
        }
    }

    public List<String> getStrains() {
        return strains;
    }

    public void setStrains(List<String> strains) {
        this.strains = strains;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public List<String> getParagraphs() {
        return paragraphs;
    }

    public void setParagraphs(List<String> paragraphs) {
        this.paragraphs = paragraphs;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "Poem{" +
                "strains=" + strains +
                ", author='" + author + '\'' +
                ", paragraphs=" + paragraphs +
                ", title='" + title + '\'' +
                '}';
    }
}
